package com.xwj.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

import java.util.Date;

/**
 * 统一日志过滤器
 *
 * @author xwj
 * @date 2020/4/9
 */
@Component
public class LogGatewayFilter implements GlobalFilter, Ordered {
    private static final Logger logger = LoggerFactory.getLogger(LogGatewayFilter.class);

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        logger.info("LogGatewayFilter:{}", new Date());
        logger.info("request:{}", exchange.getRequest());
        // TODO 可以进行鉴权等操作
        return chain.filter(exchange);
    }

    @Override
    public int getOrder() {
        return 0;
    }
}
